options(warn=-1)
library(tidyr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(plotly)
## Loading required package: ggplot2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(rworldmap)
## Loading required package: sp
## ### Welcome to rworldmap ###
## For a short introduction type :   vignette('rworldmap')
library(maps)
library(ggmap)
## 
## Attaching package: 'ggmap'
## The following object is masked from 'package:plotly':
## 
##     wind
library(reshape2)
## 
## Attaching package: 'reshape2'
## The following object is masked from 'package:tidyr':
## 
##     smiths
library(raster)
## 
## Attaching package: 'raster'
## The following object is masked from 'package:plotly':
## 
##     select
## The following object is masked from 'package:dplyr':
## 
##     select
## The following object is masked from 'package:tidyr':
## 
##     extract
library(rgdal)
## rgdal: version: 1.2-8, (SVN revision 663)
##  Geospatial Data Abstraction Library extensions to R successfully loaded
##  Loaded GDAL runtime: GDAL 2.1.3, released 2017/20/01
##  Path to GDAL shared files: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rgdal/gdal
##  Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
##  Path to PROJ.4 shared files: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rgdal/proj
##  Linking to sp version: 1.2-4
library(rgeos)
## rgeos version: 0.3-23, (SVN revision 546)
##  GEOS runtime version: 3.6.1-CAPI-1.10.1 r0 
##  Linking to sp version: 1.2-4 
##  Polygon checking: TRUE
library(ggmosaic)
## Loading required package: productplots
## 
## Attaching package: 'productplots'
## The following object is masked from 'package:raster':
## 
##     mosaic
## 
## Attaching package: 'ggmosaic'
## The following objects are masked from 'package:productplots':
## 
##     ddecker, hspine, mosaic, prodcalc, spine, vspine
## The following object is masked from 'package:raster':
## 
##     mosaic
terr = read.csv('~/Downloads/globalterrorismdb_0617dist.csv', check.names = FALSE, header = TRUE, stringsAsFactors = FALSE)
terr=rename(terr, id=eventid, year=iyear, nation=country_txt, 
            Region=region_txt, attack=attacktype1_txt,
            target=targtype1_txt, weapon=weaptype1_txt, 
            Killed=nkill, wounded=nwound)

0.1 Data cleaning

We clean the data

terr$Killed=as.integer(terr$Killed)
terr$wounded=as.integer(terr$wounded)

terr$Killed[which(is.na(terr$Killed))] = 0
terr$wounded[which(is.na(terr$wounded))] = 0

terr$casualties=as.integer(terr$Killed+terr$wounded)

terr$nation[terr$nation=="United States"] <- "USA"
terr$nation[terr$nation=="United Kingdom"] <- "UK"
terr$nation[terr$nation=="People's Republic of the Congo"] <- "Republic of Congo"
terr$nation[terr$nation=="Bosnia-Herzegovina"] <- "Bosnia and Herzegovina"
terr$nation[terr$nation=="Slovak Republic"] <- "Slovakia"
global_t <- 
  terr %>%
  group_by(year,nation,Region) %>%
  summarize(Total=n())

global_y <- 
  global_t %>% 
  group_by(year) %>% 
  summarize(Total=sum(Total))

global_attacks <- 
  global_t %>%
  group_by(nation) %>%
  summarize(Total=sum(Total)) %>% 
  arrange(desc(Total))

attach(global_attacks)
global_n <- global_attacks[order(-Total),]
detach(global_attacks)

Let’s look at the number of terrorist attacks with the passage of time.

gy <- global_y %>%
  ggplot(mapping=aes(year,Total))+
  geom_line(color="red")+
  theme(legend.position="none", panel.background = NULL, axis.text.x = element_text(angle=45, vjust = 1))+
  labs(x="Year", y="Number of attacks", title="Number of global attacks over years")
ggplotly(gy, width = 800, height=480)
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`
global_kills_years <- 
  terr %>%
  group_by(year) %>%
  summarize(killed=sum(Killed))

global_wound_years <- 
  terr %>%
  group_by(year) %>%
  summarize(wounded=sum(wounded))

globe <- 
  global_kills_years %>% 
  inner_join(global_wound_years, by="year") %>%
  inner_join(global_y)
## Joining, by = "year"
df <- melt(globe, "year")
df=rename(df, effect=variable)

gky <- df %>%
  ggplot(mapping=aes(x=year,y=value, color=effect))+
  geom_line()+
  theme(panel.background = NULL, axis.text.x = element_text(angle=45, vjust = 1))+
  labs(x="Year", y="Count", title="Number of people killed/wounded over years against attacks")
ggplotly(gky, width = 800, height=450)
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

High peaks can be seen in the people killed in the year 1984. In 2001, even though there was a fall in no. of terrorist attacks, the number of casualties were on a peak. Number of casualties suddenly started rising from 2011 to 2015.

0.2 attacks by highest casualties(killed+wounded)

#get weapon most used in each nation
terr$casualties=as.integer(terr$Killed+terr$wounded)
terr$casualties[which(is.na(terr$casualties))]=0
g_max_cas <- terr%>%
  top_n(10, casualties) %>%
  ggplot(mapping=aes(x=reorder(target1, -casualties), y=casualties, fill=target1)) +
  geom_bar(stat = 'identity')+
  theme(legend.position="none", panel.background = NULL, axis.text.x =  element_text(angle=50, vjust = 1))+
  labs(x="Target of attack", y="Number of casulaties", title="Terrorist attacks with most casualties")
ggplotly(g_max_cas)
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

0.3 Terrorist groups whose attacks have lead to most casualties

gname_max_cas <- terr[c('gname', 'casualties')]%>%
  filter(gname!='Unknown') %>%
  group_by(gname) %>%
  summarize(Total=n())

g <- gname_max_cas %>%
  top_n(40, Total) %>%
  ggplot(mapping=aes(x=reorder(gname, -Total), y=Total, fill=gname)) +
  geom_bar(stat = 'identity')+
  theme(legend.position="none", panel.background = NULL, axis.text.x =  element_text(angle=50, vjust = 1))+
  labs(x="Terrorist group", y="Number of casulaties", title="Terrorist groups leading to most casualties")
ggplotly(g, width = 800, height = 450)
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

Let’s look at the 40 countries with maximum number of terrorist attacks, and 40 countries with least number of terrorist attacks

g2 <- global_n%>%
  top_n(40) %>%
  ggplot(mapping=aes(x=reorder(nation, -Total),y=Total,fill=nation)) + 
  geom_bar(stat='identity')+
  theme(legend.position="none", panel.background = NULL, axis.text.x = element_text(angle=90, vjust = 1))+
  labs(x="Countries", y="Number of attacks", title="Countries with most number of terrorist attacks")
## Selecting by Total
ggplotly(g2, width = 800, height=450)
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`
g2 <- global_n%>%
  top_n(-40)%>%
  ggplot(mapping=aes(x=reorder(nation, Total),y=Total,fill=nation)) + 
  geom_bar(stat='identity')+
  theme(legend.position="none", panel.background = NULL, axis.text.x = element_text(angle=90, vjust = 1))+
  labs(x="Countries", y="Number of attacks", title="Countries with least number of terrorist attacks")
## Selecting by Total
ggplotly(g2, width = 800, height=450)
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

1 Relationships and inferences

We’ll take a look at relationship of some parameters. These relations, however, do not directly imply causation. Further analysis should be done for implying causation.

1.1 Casualties by region

g1 <- terr %>% 
  ggplot(aes(x = Region, y = casualties, fill=Region)) + 
  geom_boxplot() +
  theme(legend.position = "none", axis.text.x =  element_text(angle=45))

ylim1 = boxplot.stats(terr$casualties)$stats[c(1,5)]
g2 <- g1+coord_cartesian(ylim = ylim1*1.05)
ggplotly(g2)
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

We can see that Middle East & North Africa has a higher median number of casualties(2) than other regions, which same as that for Sub-Saharan Africa. The least variant region in terms of number of casualties is North America. However, it has lot many outliers, with the 9/11 attacks resulting in most number of casualties(8749).

1.2 Casualties by attack type

g1 <- terr %>% 
  ggplot(aes(x = attack, y = casualties, fill=attack)) + 
  geom_boxplot() +
  theme(legend.position = "none", axis.text.x =  element_text(angle=45))

ylim1 = boxplot.stats(terr$casualties)$stats[c(1,5)]
g2 <- g1+coord_cartesian(ylim = ylim1*1.05)
ggplotly(g2, height = 500)
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

Leaving out the unknown attack types, no. of casualties are most highly variant in case of bombings/explosions. Hijacking and Hostage Taking(s) have low variance in no. of casualties, with outliers as high as 8749 in case of hijacking.

1.3 Casualties by weapon

g1 <- terr %>% 
  ggplot(aes(x = weapon, y = casualties, fill=weapon)) + 
  geom_boxplot() +
  theme(legend.position = "none", axis.text.x =  element_text(angle=45))

ylim1 = boxplot.stats(terr$casualties)$stats[c(1,5)]
g2 <- g1+coord_cartesian(ylim = ylim1*1.05)
ggplotly(g2, height = 500)
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

The no. of casualties because of chemical weapons has been highly variant, with 25% of chemical attacks resultin casualties between 50 to 5513. There hasn’t been any casualty because of radilogical weapons.

1.4 Casualties by target

g1 <- terr %>% 
  ggplot(aes(x = target, y = casualties, fill=target)) + 
  geom_boxplot() +
  theme(legend.position = "none", axis.text.x =  element_text(angle=45))

ylim1 = boxplot.stats(terr$casualties)$stats[c(1,5)]
g2 <- g1+coord_cartesian(ylim = ylim1*1.05)
ggplotly(g2, height = 500)
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

Casualties related to transporation, military, and Private citizens & property have high variance. Attacks on Police, and non-state militia generally lead to more than 1 casualty, with as many as 11 casualties in some cases.

1.5 Casualties by type of attack

g1 <- terr %>% 
  filter(INT_ANY!=-9)%>%
  ggplot(aes(x = factor(INT_ANY), y = casualties, fill=INT_ANY)) + 
  geom_boxplot() +
  theme(legend.position = "none", axis.text.x =  element_text(angle=45))

ylim1 = boxplot.stats(terr$casualties)$stats[c(1,5)]
g2 <- g1+coord_cartesian(ylim = ylim1*1.05)
ggplotly(g2, height = 500)
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

Domestic attacks usually had higher number of casualties as compared to attacks that were international on any level, i.e. logistics, ideological, or miscellaneous reason.

#getting proportions across attack and region
t = table(data.frame(terr$attack,terr$Region));
prop.table(t,2)*100
##                                      terr.Region
## terr.attack                           Australasia & Oceania
##   Armed Assault                                  18.5606061
##   Assassination                                  11.3636364
##   Bombing/Explosion                              27.6515152
##   Facility/Infrastructure Attack                 25.3787879
##   Hijacking                                       1.1363636
##   Hostage Taking (Barricade Incident)             1.8939394
##   Hostage Taking (Kidnapping)                     4.1666667
##   Unarmed Assault                                 3.7878788
##   Unknown                                         6.0606061
##                                      terr.Region
## terr.attack                           Central America & Caribbean
##   Armed Assault                                        42.1663443
##   Assassination                                        12.1179884
##   Bombing/Explosion                                    31.3249516
##   Facility/Infrastructure Attack                        3.8781431
##   Hijacking                                             0.2514507
##   Hostage Taking (Barricade Incident)                   1.8085106
##   Hostage Taking (Kidnapping)                           4.8452611
##   Unarmed Assault                                       0.1837524
##   Unknown                                               3.4235977
##                                      terr.Region
## terr.attack                           Central Asia  East Asia
##   Armed Assault                         20.7581227 14.3576826
##   Assassination                         20.5776173  6.9269521
##   Bombing/Explosion                     41.6967509 41.1838791
##   Facility/Infrastructure Attack         3.4296029 24.9370277
##   Hijacking                              1.4440433  2.2670025
##   Hostage Taking (Barricade Incident)    0.3610108  0.3778338
##   Hostage Taking (Kidnapping)            8.1227437  1.7632242
##   Unarmed Assault                        0.7220217  5.2896725
##   Unknown                                2.8880866  2.8967254
##                                      terr.Region
## terr.attack                           Eastern Europe
##   Armed Assault                           24.9254621
##   Assassination                            7.6724309
##   Bombing/Explosion                       54.0647983
##   Facility/Infrastructure Attack           4.7505466
##   Hijacking                                0.5167959
##   Hostage Taking (Barricade Incident)      0.3975353
##   Hostage Taking (Kidnapping)              4.2933810
##   Unarmed Assault                          1.1329756
##   Unknown                                  2.2460743
##                                      terr.Region
## terr.attack                           Middle East & North Africa
##   Armed Assault                                       18.7912537
##   Assassination                                        8.7291178
##   Bombing/Explosion                                   60.8759218
##   Facility/Infrastructure Attack                       2.2553804
##   Hijacking                                            0.2709037
##   Hostage Taking (Barricade Incident)                  0.1870525
##   Hostage Taking (Kidnapping)                          5.1966202
##   Unarmed Assault                                      0.3526048
##   Unknown                                              3.3411451
##                                      terr.Region
## terr.attack                           North America South America
##   Armed Assault                          12.1338912    20.3816224
##   Assassination                           7.0830843    14.4600789
##   Bombing/Explosion                      45.6664674    47.8467114
##   Facility/Infrastructure Attack         26.0609683     4.1360196
##   Hijacking                               0.5379558     0.3517749
##   Hostage Taking (Barricade Incident)     1.8828452     1.2205522
##   Hostage Taking (Kidnapping)             3.6162582     7.3446328
##   Unarmed Assault                         2.0621638     0.2505063
##   Unknown                                 0.9563658     4.0081015
##                                      terr.Region
## terr.attack                           South Asia Southeast Asia
##   Armed Assault                       25.5536545     32.6202742
##   Assassination                        9.5597272     10.8006636
##   Bombing/Explosion                   47.7962262     39.0814634
##   Facility/Infrastructure Attack       4.5738246      7.3168602
##   Hijacking                            0.2048341      0.3754475
##   Hostage Taking (Barricade Incident)  0.2409813      0.4103728
##   Hostage Taking (Kidnapping)          7.2342579      5.8412643
##   Unarmed Assault                      0.6723378      0.2008207
##   Unknown                              4.1641564      3.3528333
##                                      terr.Region
## terr.attack                           Sub-Saharan Africa Western Europe
##   Armed Assault                               34.6265574     10.1612804
##   Assassination                                9.3021755     17.8389649
##   Bombing/Explosion                           31.8249306     51.6587968
##   Facility/Infrastructure Attack               4.5897618     15.4105599
##   Hijacking                                    0.7488219      0.3863372
##   Hostage Taking (Barricade Incident)          0.4712414      0.5273809
##   Hostage Taking (Kidnapping)                 10.2640243      1.6495983
##   Unarmed Assault                              0.4712414      0.7726743
##   Unknown                                      7.7012459      1.5944073
g <- ggplot(data=terr) +
  geom_mosaic(aes(fill = attack, x = product(Region)))+
  labs(x = "Attack type", y = "Proportion")+
  coord_flip()+
  theme(legend.position = "none", panel.background = NULL, axis.text.y = element_text(angle=50, vjust=1))
#g
ggplotly(g, height = 500)
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

Middle East & North Africa have higher proportion of bombings/explosions(60%) than any other region, followed by Eastern Europe(54%). Central America and Caribbean have a high percentage of armed assaults(42%).

#getting proportions across attack and region
t = table(data.frame(terr$attack,terr$target));
prop.table(t,2)*100
##                                      terr.target
## terr.attack                           Abortion Related Airports & Aircraft
##   Armed Assault                             3.04182510          7.65765766
##   Assassination                             3.42205323          1.20120120
##   Bombing/Explosion                        19.01140684         58.40840841
##   Facility/Infrastructure Attack           73.00380228          7.05705706
##   Hijacking                                 0.00000000         19.81981982
##   Hostage Taking (Barricade Incident)       0.38022814          1.05105105
##   Hostage Taking (Kidnapping)               0.38022814          1.35135135
##   Unarmed Assault                           0.76045627          0.45045045
##   Unknown                                   0.00000000          3.00300300
##                                      terr.target
## terr.attack                              Business Educational Institution
##   Armed Assault                       11.51310824             13.75000000
##   Assassination                        4.81557893              8.53365385
##   Bombing/Explosion                   58.63734715             51.85096154
##   Facility/Infrastructure Attack      13.95360539             13.94230769
##   Hijacking                            0.30191717              0.21634615
##   Hostage Taking (Barricade Incident)  0.88059176              0.76923077
##   Hostage Taking (Kidnapping)          7.50767373              7.76442308
##   Unarmed Assault                      0.28178936              1.70673077
##   Unknown                              2.10838827              1.46634615
##                                      terr.target
## terr.attack                           Food or Water Supply
##   Armed Assault                                13.81578947
##   Assassination                                 0.00000000
##   Bombing/Explosion                            66.77631579
##   Facility/Infrastructure Attack               11.84210526
##   Hijacking                                     1.31578947
##   Hostage Taking (Barricade Incident)           0.65789474
##   Hostage Taking (Kidnapping)                   2.30263158
##   Unarmed Assault                               1.64473684
##   Unknown                                       1.64473684
##                                      terr.target
## terr.attack                           Government (Diplomatic)
##   Armed Assault                                   17.66939252
##   Assassination                                   10.04672897
##   Bombing/Explosion                               47.80957944
##   Facility/Infrastructure Attack                   8.32359813
##   Hijacking                                        0.67172897
##   Hostage Taking (Barricade Incident)              1.66471963
##   Hostage Taking (Kidnapping)                      9.11214953
##   Unarmed Assault                                  0.99299065
##   Unknown                                          3.70911215
##                                      terr.target
## terr.attack                           Government (General)
##   Armed Assault                                16.23510879
##   Assassination                                27.65580388
##   Bombing/Explosion                            39.30786650
##   Facility/Infrastructure Attack                6.45367727
##   Hijacking                                     0.06399527
##   Hostage Taking (Barricade Incident)           0.32489908
##   Hostage Taking (Kidnapping)                   7.42345181
##   Unarmed Assault                               0.56118933
##   Unknown                                       1.97400807
##                                      terr.target
## terr.attack                           Journalists & Media    Maritime
##   Armed Assault                               13.32858161 22.48520710
##   Assassination                               24.41197434  3.25443787
##   Bombing/Explosion                           26.44333571 39.05325444
##   Facility/Infrastructure Attack               6.87811832  3.25443787
##   Hijacking                                    0.10691376 14.20118343
##   Hostage Taking (Barricade Incident)          8.33927299  0.59171598
##   Hostage Taking (Kidnapping)                 16.00142552 12.72189349
##   Unarmed Assault                              1.56806842  0.00000000
##   Unknown                                      2.92230934  4.43786982
##                                      terr.target
## terr.attack                              Military         NGO       Other
##   Armed Assault                       40.51670064 23.46491228 28.98550725
##   Assassination                        6.06476400  8.77192982  0.80515298
##   Bombing/Explosion                   42.15148189 23.13596491 36.07085346
##   Facility/Infrastructure Attack       1.19178297  7.34649123 17.39130435
##   Hijacking                            0.08232711  0.54824561  0.48309179
##   Hostage Taking (Barricade Incident)  0.10976948  0.65789474  0.64412238
##   Hostage Taking (Kidnapping)          2.52077780 31.79824561  9.17874396
##   Unarmed Assault                      0.31362710  0.87719298  2.09339775
##   Unknown                              7.04876901  3.39912281  4.34782609
##                                      terr.target
## terr.attack                                Police
##   Armed Assault                       36.14090156
##   Assassination                       12.06731188
##   Bombing/Explosion                   41.57729532
##   Facility/Infrastructure Attack       2.00540588
##   Hijacking                            0.06103409
##   Hostage Taking (Barricade Incident)  0.20054059
##   Hostage Taking (Kidnapping)          2.85552359
##   Unarmed Assault                      0.33132793
##   Unknown                              4.76065917
##                                      terr.target
## terr.attack                           Private Citizens & Property
##   Armed Assault                                       25.22878432
##   Assassination                                       10.14902235
##   Bombing/Explosion                                   46.77701655
##   Facility/Infrastructure Attack                       3.28049207
##   Hijacking                                            0.13752063
##   Hostage Taking (Barricade Incident)                  0.31504726
##   Hostage Taking (Kidnapping)                          9.18887833
##   Unarmed Assault                                      0.75011252
##   Unknown                                              4.17312597
##                                      terr.target
## terr.attack                           Religious Figures/Institutions
##   Armed Assault                                          18.88994759
##   Assassination                                          10.60028585
##   Bombing/Explosion                                      47.87994283
##   Facility/Infrastructure Attack                         13.62553597
##   Hijacking                                               0.02382087
##   Hostage Taking (Barricade Incident)                     0.52405908
##   Hostage Taking (Kidnapping)                             5.59790376
##   Unarmed Assault                                         0.66698428
##   Unknown                                                 2.19151977
##                                      terr.target
## terr.attack                           Telecommunication
##   Armed Assault                              5.29531568
##   Assassination                              0.40733198
##   Bombing/Explosion                         60.59063136
##   Facility/Infrastructure Attack            27.08757637
##   Hijacking                                  0.00000000
##   Hostage Taking (Barricade Incident)        3.66598778
##   Hostage Taking (Kidnapping)                1.73116090
##   Unarmed Assault                            0.20366599
##   Unknown                                    1.01832994
##                                      terr.target
## terr.attack                           Terrorists/Non-State Militia
##   Armed Assault                                        24.69394893
##   Assassination                                        22.10563134
##   Bombing/Explosion                                    40.15389997
##   Facility/Infrastructure Attack                        0.94438615
##   Hijacking                                             0.00000000
##   Hostage Taking (Barricade Incident)                   0.10493179
##   Hostage Taking (Kidnapping)                           5.66631689
##   Unarmed Assault                                       0.13990906
##   Unknown                                               6.19097587
##                                      terr.target
## terr.attack                              Tourists Transportation
##   Armed Assault                       20.51282051    21.28586450
##   Assassination                        8.39160839     0.87126333
##   Bombing/Explosion                   41.02564103    63.94772420
##   Facility/Infrastructure Attack       3.03030303     8.74267688
##   Hijacking                            0.69930070     0.99143758
##   Hostage Taking (Barricade Incident)  1.16550117     0.43563167
##   Hostage Taking (Kidnapping)         22.84382284     1.12663362
##   Unarmed Assault                      0.93240093     0.66095839
##   Unknown                              1.39860140     1.93780982
##                                      terr.target
## terr.attack                               Unknown   Utilities
##   Armed Assault                        3.18079212  1.96648427
##   Assassination                        4.28893905  0.06839945
##   Bombing/Explosion                   89.32895547 90.80027360
##   Facility/Infrastructure Attack       0.69772214  4.78796170
##   Hijacking                            0.10260620  0.01709986
##   Hostage Taking (Barricade Incident)  0.04104248  0.18809850
##   Hostage Taking (Kidnapping)          0.73876462  0.42749658
##   Unarmed Assault                      0.24625487  0.00000000
##   Unknown                              1.37492305  1.74418605
##                                      terr.target
## terr.attack                           Violent Political Party
##   Armed Assault                                   24.63599301
##   Assassination                                   32.61502621
##   Bombing/Explosion                               26.49970879
##   Facility/Infrastructure Attack                   4.71753058
##   Hijacking                                        0.00000000
##   Hostage Taking (Barricade Incident)              0.05824112
##   Hostage Taking (Kidnapping)                      6.52300524
##   Unarmed Assault                                  0.58241118
##   Unknown                                          4.36808387
g <- ggplot(data=terr) +
  geom_mosaic(aes(fill = attack, x = product(target)))+
  labs(x = "Attack type", y = "Proportion")+
  coord_flip()+
  theme(legend.position = "none", panel.background = NULL, axis.text.y = element_blank())#element_text(angle=50, vjust=1))
#g
ggplotly(g, height = 500)
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

Targets like utilities, transportation, ans business are mostly attacked by bombings or explosions.

#getting proportions across attack and region
attacks_known_ntnlty <- terr %>%
  filter(INT_ANY != -9)
t = table(data.frame(attacks_known_ntnlty$INT_ANY,attacks_known_ntnlty$Region));
prop.table(t,2)*100
##                             attacks_known_ntnlty.Region
## attacks_known_ntnlty.INT_ANY Australasia & Oceania
##                            0              28.22581
##                            1              71.77419
##                             attacks_known_ntnlty.Region
## attacks_known_ntnlty.INT_ANY Central America & Caribbean Central Asia
##                            0                    89.31891     28.20513
##                            1                    10.68109     71.79487
##                             attacks_known_ntnlty.Region
## attacks_known_ntnlty.INT_ANY East Asia Eastern Europe
##                            0  64.34783       24.68293
##                            1  35.65217       75.31707
##                             attacks_known_ntnlty.Region
## attacks_known_ntnlty.INT_ANY Middle East & North Africa North America
##                            0                   43.70093      50.87918
##                            1                   56.29907      49.12082
##                             attacks_known_ntnlty.Region
## attacks_known_ntnlty.INT_ANY South America South Asia Southeast Asia
##                            0      88.90164   79.72249       87.02144
##                            1      11.09836   20.27751       12.97856
##                             attacks_known_ntnlty.Region
## attacks_known_ntnlty.INT_ANY Sub-Saharan Africa Western Europe
##                            0           62.86338       18.48627
##                            1           37.13662       81.51373
g <- ggplot(data=attacks_known_ntnlty) +
  geom_mosaic(aes(fill = factor(INT_ANY), x = product(Region)))+
  labs(x = "Region", y = "Proportion")+
  coord_flip()+
  theme(legend.position = "none", panel.background = NULL, axis.text.y = element_blank())#element_text(angle=50, vjust=1))
#g
ggplotly(g)
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

Western Europe had a fairly high number of international attacks(81%) as compared to domestic attacks, followed by Middle East & North Africa(56%). More than 87% of terrorist attacks in Central America & Caribbean Central, South America, and Southeast Asia were domestic.

1.6 Ideology or logistics of attacks in top 10 most attacked countries

#getting proportions across attack and region
most_attacked <- global_n %>%
  top_n(10, Total)

most_attacked_nations <- terr %>%
  filter(nation %in% most_attacked$nation & INT_ANY!=-9)


t = table(data.frame(most_attacked_nations$INT_ANY,most_attacked_nations$nation));
prop.table(t,2)*100
##                              most_attacked_nations.nation
## most_attacked_nations.INT_ANY Afghanistan   Colombia El Salvador
##                             0   73.771340  91.878634   96.179183
##                             1   26.228660   8.121366    3.820817
##                              most_attacked_nations.nation
## most_attacked_nations.INT_ANY      India       Iraq   Pakistan       Peru
##                             0  84.775549  18.645027  79.741120  94.268128
##                             1  15.224451  81.354973  20.258880   5.731872
##                              most_attacked_nations.nation
## most_attacked_nations.INT_ANY Philippines     Turkey         UK
##                             0   92.719056  85.027125   0.000000
##                             1    7.280944  14.972875 100.000000
g <- ggplot(data=most_attacked_nations) +
  geom_mosaic(aes(fill = factor(INT_ANY), x = product(nation)))+
  labs(x = "Region", y = "Proportion")+
  coord_flip()+
  theme(legend.position = "none", panel.background = NULL, axis.text.y = element_blank())#element_text(angle=50, vjust=1))

ggplotly(g)
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

When looking at the attacks of the top 10 most attacked countries, we are looking at the attacks whose ideological or logistical nationality we know. All of the attacks in UK are international. After that, 81% of attacks in Iraq are logistically or ideologically international. More than 96% of the attacks in El Salvador, and more than 90% of the attacks in Columbia, Peru and Phillipines, are domestic.